package com.gec.zhs.controller;


import com.gec.zhs.entity.query.VideoCommentQuery;
import com.gec.zhs.entity.query.VideoDanmuQuery;
import com.gec.zhs.entity.vo.PaginationResultVO;
import com.gec.zhs.entity.vo.ResponseVO;
import com.gec.zhs.service.VideoCommentService;
import com.gec.zhs.service.VideoDanmuService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

/**
 * @author zhs
 * @version 1.0
 * @date 2025-03-20
 * @description 互动
 */
@RestController
@RequestMapping("/interact")
@Validated
public class InteractController extends ABaseController {

    @Autowired
    private VideoCommentService videoCommentService;

    @Autowired
    private VideoDanmuService videoDanmuService;

    @ApiOperation("加载弹幕")
    @RequestMapping("/loadDanmu")
    public ResponseVO loadDanmu(Integer pageNo, String videoNameFuzzy) {
        VideoDanmuQuery danmuQuery = new VideoDanmuQuery();
        danmuQuery.setOrderBy("danmu_id desc");
        danmuQuery.setPageNo(pageNo);
        danmuQuery.setQueryVideoInfo(true);
        danmuQuery.setVideoNameFuzzy(videoNameFuzzy);
        PaginationResultVO resultVO = videoDanmuService.findListByPage(danmuQuery);
        return getSuccessResponseVO(resultVO);
    }

    @ApiOperation("删除弹幕")
    @RequestMapping("/delDanmu")
    public ResponseVO delDanmu(@NotNull Integer danmuId) {
        videoDanmuService.deleteDanmu(null, danmuId);
        return getSuccessResponseVO(null);
    }

    @ApiOperation("加载评论")
    @RequestMapping("/loadComment")
    public ResponseVO loadComment(Integer pageNo, String videoNameFuzzy) {
        VideoCommentQuery commentQuery = new VideoCommentQuery();
        commentQuery.setOrderBy("comment_id desc");
        commentQuery.setPageNo(pageNo);
        commentQuery.setQueryVideoInfo(true);
        commentQuery.setVideoNameFuzzy(videoNameFuzzy);
        PaginationResultVO resultVO = videoCommentService.findListByPage(commentQuery);
        return getSuccessResponseVO(resultVO);
    }

    @ApiOperation("删除评论")
    @RequestMapping("/delComment")
    public ResponseVO delComment(@NotNull Integer commentId) {
        videoCommentService.deleteComment(commentId, null);
        return getSuccessResponseVO(null);
    }
}
